/*
 * AddPersonDialog.cpp
 *
 *  Created on: 11.04.2010
 *      Author: king
 */

#include <QtGui>
#include "AddPersonDialog.h"
#include "genealogy_tree/Gender.h"
#include "common/Date.h"

namespace etu {
namespace ui {

using etu::common::Date;
using etu::genealogy_tree::Gender;

CAddPersonDialog::CAddPersonDialog(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);
    m_personWidget->m_commentGroup->setVisible(false);
    setMaximumWidth(m_personWidget->minimumSizeHint().width());
    setMaximumHeight(minimumSizeHint().height());
}

void CAddPersonDialog::accept()
{
  if (m_personWidget->m_nameEdit->text().isEmpty() || m_personWidget->m_lastNameEdit->text().isEmpty())
    return;

  Person* person = m_personWidget->getPerson();

  emit createNewPerson(*person, m_personType);
  emit changeEnableStatus(true);

  delete person;
  QDialog::accept();
}

void  CAddPersonDialog::showDialog(PersonType personType)
{
  Person* person = new Person();
  m_personWidget->setPerson(person);
  m_personType = personType;

  m_personWidget->m_femaleRB->setChecked(personType != etu::genealogy_tree::FATHER);
  m_personWidget->m_maleRB->setChecked(personType != etu::genealogy_tree::MOTHER);
  m_personWidget->m_maleRB->setVisible(personType != etu::genealogy_tree::MOTHER);
  m_personWidget->m_femaleRB->setVisible(personType != etu::genealogy_tree::FATHER);

  exec();
}

}
}
